﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QLDAOL.Models;
using QLDAOL.Util;
using QLDAOL.ModelView;

namespace QLDAOL.Controllers
{
    public class ProjectController : BaseController
    {
        //
        // GET: /Index/
        public IEQLDAOLRepository repository = new IEQLDAOLRepository();
        public ActionResult ProjectPage(int ID_PJ=0)
        {
            int userID = 1; //Danh
            bool checkaccess=false;
            if(ID_PJ>0)  
                checkaccess= repository.checkPJAccess(ID_PJ, userID);
            if (checkaccess)
            {
                Session["pjID"] = ID_PJ;
                ViewData["pj"] = ID_PJ;
                bool ispm = repository.ispm(ID_PJ, userID);
                ViewData["ispm"] = ispm;
                return View();
            }
            return RedirectToAction("AccessDenied");
        }
        public ActionResult sidebar()
        {
            
            return PartialView();
        }
        public ActionResult ProjectSupporter()
        {
            int id = int.Parse(Session["pjID"].ToString());
            var lstSupporter = repository.getlstSupporter(id);
            ViewData["lstPJSupporter"] = lstSupporter;
            return PartialView();
        }
        public ActionResult InfomationContent( int type = 1 )
        {
            int id = int.Parse(Session["pjID"].ToString());
            var lstInfo = repository.getlstLatestNewsQA(type, id);
            ViewData["lstInfo"] = lstInfo;
            ViewData["type"] = type;
            return PartialView();
        }
        public ActionResult AccessDenied()
        {
            return View();
        }
        public ActionResult ListPage(string pjName="", int pjLang=0)
        {
            repository.temp();
            if(Request.QueryString["pjName"]!=null)
            pjName = Request.QueryString["pjName"].ToString();
            var lstPJ= repository.getlstPJSearch(pjName,pjLang);
            ViewData["lstPJ"] = lstPJ;

            var lstPJLanguage = repository.getlstProjectLang();
            ViewData["lstPJLanguage"] = lstPJLanguage;
            return View();
        }
        public ActionResult SidebarUser()
        {
            int id = int.Parse(Session["pjID"].ToString());
            var lstUser = repository.getlst6UserByPJID(id);
            ViewData["lstUser"] = lstUser;
            return PartialView();
        }
        public ActionResult ListUserPage()
        {
            int userID = 1; //Danh
            int id = int.Parse(Session["pjID"].ToString());
            bool checkaccess = false;
            if (id > 0)
                checkaccess = repository.checkPJAccess(id, userID);
            if (checkaccess)
            {
                var lstUser = repository.getlstUserByPJID(id);
                ViewData["lstUser"] = lstUser;
                return View();
            }
            return RedirectToAction("AccessDenied");
        }
    }
}
